<template>
  <div class="box">
    <div class="img-box">
      <img class="imgCls"
           v-for="(item,index) in content"
           :src="item"
           v-show="index == current">
      <div class="dot">
        <span @click="changeImg(index)"
              v-for="(item,index) in content"
              :key="index"
              :style="{'background-color': index == current ? '#fff' : '#ccc'}"></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    content: {
      type: Array,
      default: []
    }
  },
  data () {
    return {
      current: 0
    }
  },
  mounted () {
    this.move();
  },
  methods: {
    move () {
      let len = this.content.length
      setInterval(() => {
        if (this.current < len - 1) {
          this.current++;
        } else {
          this.current = 0
        }
      }, 2500)
    },
    changeImg (key) {
      this.current = key;
    }
  }
}
</script>

<style lang="scss" scoped>
.box {
  margin-top: 20px;
  width: 100vw;
  height: 440px;
  overflow: hidden;
  box-sizing: border-box;
  .img-box {
    display: flex;
    position: relative;
    .imgCls {
      flex-shrink: 0;
      width: 100vw;
      height: 440px;
      transition: all 0.3s ease-in-out;
    }
    .dot {
      position: absolute;
      bottom: 18px;
      left: calc(50% - 250px);
      width: 500px;
      height: 10px;
      span {
        display: inline-block;
        cursor: pointer;
        width: 50px;
        height: 8px;
        border-radius: 4px;
        margin: 0 10px;
        background-color: #ccc;
      }
    }
  }
}
</style>